package org.jeecg.modules.wlhy.hyarea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.wlhy.hyarea.entity.HyArea;
import org.jeecg.modules.wlhy.hyarea.mapper.HyAreaMapper;
import org.jeecg.modules.wlhy.hyarea.service.IHyAreaService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: hy_area
 * @Author: duanlikao
 * @Date:   2021-07-02
 * @Version: V1.0
 */
@Service
public class HyAreaServiceImpl extends ServiceImpl<HyAreaMapper, HyArea> implements IHyAreaService {

    @Override
    public boolean checkAreaCode(String areaCode) {
        return this.count(new QueryWrapper<HyArea>().eq("area_code",areaCode)) > 0;
    }

    @Override
    public String getAreaNames(String areaCode) {
        LambdaQueryWrapper<HyArea> queryWrapperArea = new LambdaQueryWrapper<>();
        queryWrapperArea.eq(HyArea::getAreaCode, areaCode);
        HyArea area = this.getOne(queryWrapperArea);
        if(area!=null){
            return area.getName();
        }else{
            return "无";
        }
    }

    @Override
    public String fuzzyFindMergerName(String areaCode) {
        LambdaQueryWrapper<HyArea> queryWrapperArea = new LambdaQueryWrapper<>();
        queryWrapperArea.like(HyArea::getAreaCode, areaCode).eq(HyArea::getLevel, 2).last("limit 1");
        HyArea area = this.getOne(queryWrapperArea);
        if (area!=null) {
            return area.getMergerName();
        }else{
            return null;
        }
    }
}
